<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateBonusAPIRequest;
use App\Http\Requests\API\UpdateBonusAPIRequest;
use App\Models\Bonus;
use App\Repositories\BonusRepository;
use App\ZL\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use Illuminate\Support\Facades\Auth;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class BonusController
 * @package App\Http\Controllers\API
 */
class BonusCategoryAPIController extends ApiBaseController
{
    /** @var  BonusRepository */
    private $bonusRepository;
    private $shop_id = null;
    protected $model_name = 'App\Models\BonusCategory';
    protected $model_load_array = [
    ];
    protected $search_field_array = [
    ];

    public function __construct(BonusRepository $bonusRepo)
    {
        $this->bonusRepository = $bonusRepo;
        $this->shop_id = \request('shop_id',null);
    }


    public function authLimit()
    {
        $shop_id = \request('shop_id',false);
        $res = [];
        if($shop_id && $shop_id>0){
            $res[] =  ['shop_id', $shop_id];
        }
        return $res;
    }


    public function _after_get($data)
    {
        $user_id = Auth::id();
        foreach ($data as &$v) {
            $v->has = Bonus::where('user_id',$user_id)->where('bonus_category_id',$v->id)->get();
            $v->use = Bonus::where('user_id',$user_id)->where('bonus_category_id',$v->id)->where('use_status',2)->get();
        }
        return $data;
    }
}
